﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CodeGenerator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<string> lst2 = new List<string>();

            List<string> lst3 = new List<string>();
            lst3.Add("#region " + textBox5.Text);
 
            List<string> lst4 = new List<string>();
            foreach (string s in textBox1.Lines)
            {
                
                if (s.Contains("public"))
                {
                    string s1 = s.Trim(). Split(' ')[0];
                    string s2 = s.Trim().Split(' ')[1];
                    string s3 = s.Trim().Split(' ')[2];
                    s3 = s.Substring(s.IndexOf(s3));
                    string[] param = s3.Split(' ');

                    string newString = "{ ";
                    if (s2 != "void") newString += "return";
                    newString += " new " + textBox5.Text + "Manager()." + s3.Substring(0, s3.IndexOf("(")+1);
                    for (int i = 1; i < param.Length; i += 2) newString += param[i];
                    if (param.Length == 1) newString += ")";
                    newString += ";}";
                        
                    

                    lst2.Add(s.Trim());
                    lst2.Add(newString);
                    lst2.Add("");

                    lst3.Add("[OperationContract]");
                    lst3.Add(s2 + " " + s3 + ";");
                    lst3.Add("");

                    lst4.Add(s.Trim());
                    lst4.Add("{");
                    lst4.Add("");
                    lst4.Add("}");
                    lst4.Add("");
                }
            
            }
            textBox2.Lines = lst2.ToArray();

            lst3.Add("#endregion");
            textBox3.Lines = lst3.ToArray();
            textBox4.Lines = lst4.ToArray();
        }
    }
}
